import { ref, onMounted, computed, reactive, watch } from "vue"
import { useRoute ,useRouter} from 'vue-router';
import *  as util from '@/amtf/utils'

export default function (cfg = {}) {
  const currentRoute = useRoute();
  // console.log(`currentRoute 👉`, currentRoute)
  const router = useRouter();

  const a = reactive({
    当前url: "",
  })

  const 主路由 = computed(() => {
    let 全部路由 = router.getRoutes()
    // console.log(`全部路由 👉`, 全部路由)
    let layout = util.查元素(全部路由, 'layout', 'name')
    // console.log(`layout 👉`, layout)
    // let res = util.查元素(layout.children, 主页路由name.value, 'name')
    // console.log(`返回主页res 👉`, res)
    return layout
  })

  const 主页路由name = computed(() => {
    // let res = userInfo.value.authority.defaultRouter
    // if (!res) {
    //   // router 的name
    //   res = "home"
    // }
    return "home"
  })

  const 主页路由 = computed(() => {
    let 全部路由 = router.getRoutes()
    // console.log(`全部路由 👉`, 全部路由)
    let layout = util.查元素(全部路由, 'layout', 'name')
    // console.log(`layout 👉`, layout)
    let res = util.查元素(layout.children, 主页路由name.value, 'name')
    console.log(`返回主页res 👉`, res)
    return res
  })

  return {
    主页路由name,
    主页路由,
    主路由,
    currentRoute,
    a,
  }

}






